package com.atguigu.gulimall.product.controller;

import com.atguigu.common.utils.R;
import com.atguigu.gulimall.product.entity.CategoryEntity;
import com.atguigu.gulimall.product.service.CategoryService;
import com.atguigu.gulimall.product.vo.Catelog2Vo;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@RestController
public class ShouyeController {
    @Resource
    private CategoryService categoryService;
//    @GetMapping({"/","/index.html"})
//    public String getLevel1Categorys(Model model){
//        List<CategoryEntity> categoryEntityList = categoryService.getLevel1Categorys();
//        model.addAttribute("categorys", categoryEntityList);
//        return "index";
//    }

    /**
     * 获取所有的以及分类****
     * @return
     *  @GetMapping({"/","/index.html"})
     */
    @GetMapping("/shouye2")
    public R getLevel1Categorys(Model model){
        List<CategoryEntity> categoryEntityList = categoryService.getLevel1Categorys();
        return R.ok().put("data",categoryEntityList);
    }

    /**
     * 获取分类的json格式数据（包括一级+二级+三级分类）****
     * @return
     */
    @GetMapping("/index/catalogJson")
    public R getCatalogJson(){
        Map<String, List<Catelog2Vo>> catalogJson = categoryService.getCatalogJson();
        return R.ok().put("data",catalogJson);
    }


}
